#include <iostream>

int test1()
{
	/*
	 * 不要给无符号类型赋一个负值
	 * 也要避免程序运行过程中出现这种情况
	 */
	unsigned u = 10, u2 = 42;
	std::cout << u2 - u << std::endl;
	std::cout << u - u2 << std::endl;

	int i = 10, i2 = 42;
	std::cout << i2 - i << std::endl;
	std::cout << i - i2 << std::endl;
	std::cout << i - u << std::endl;
	std::cout << u - i << std::endl;
	return 0;
}

int test2()
{
	std::cout << "a really, really long string literal "
			"that spans two lines \n test" << std::endl;
	return 0;
}

int test3()
{
	std::cout << 'a' << " " << L'a' << " " << "a" << " " <<  " " << L"a" << std::endl;
	std::cout << 10 << 10u << 10L << 10ul << 012 << 0xC << std::endl;
	std::cout << 3.14L << std::endl;
	int a;  // 这里为随机值
	std::cout << a;
	return 0;
}

int t_2_9_10()
{
	int input_value;
	std::cin >> input_value;
	std::cout << input_value << std::endl;
	return 0;
}

extern double pi = 3.14;
int t_2_2()
{
//	extern double pi = 3.14;
	std::cout << pi << std::endl;
	return 0;
}

int t_3_2()
{
	int i = 42;
	int *p1 = &i;
	*p1 = *p1 * *p1;
	std::cout << "*p1: " << *p1 << std::endl
			<< "p1: " << p1 << std::endl;

	int *ptr = nullptr;
	if (ptr)
	{
		std::cout << "because ptr is not 空指针！" << std::endl;
	}
	else if (!ptr)
	{
		std::cout << "because ptr is 空指针！" << std::endl;
	}
	return 0;
}

int t_4_2()
{
	const double pi = 3.14;
	int num = 10, num_2 = 20;
//	double *ptr = &pi;  // 错误，ptr是一个普通指针
//	const double *cptr = &pi;
	const double *const pip = &pi;  // 指针本身的值不可改变（即不可指向另一个对象）， 同时无法通过pip来修改pi的值
	int *const iptr = &num;
//	iptr = &num_2;
	const int &cp = 10;
	const int p = 10;  // const常量必须初始化
	const int* p1;  // const指针常量可以不初始化，因为指针是可以变得
	return 0;
}

int t_4_4()
{
	int null = 0;
//	constexpr int *p = nullptr;  // constexpr的初始值必须是0, nullptr
	return 0;
}

int t_5_2()
{
	const int i = 42;
	int b = 10;
	auto *p = &i;
//	*p = 10;
	p = &b;
	std::cout << "*p: " << p << std::endl;
	return 0;
}

int t_5_3()
{

	int a{3}, b{3};
	decltype((b)) d = a;
	std::cout << "d: " << ++d << "\t"
			<< "a: " << a << std::endl;

	decltype(a = b) f = a;
	std::cout << "f: " << f << std::endl;
	return 0;
}

std::string g_str;    //初始化为一个空串
int g_int;  // 初始化为0
int main02()
{
//	t_2_9_10();
	std::string l_str;    //初始化为一个空串
//	int l_int, wage;
//	double salary = wage = 9999.99;
//	std::cout << g_str << std::endl << g_int << std::endl;
//	std::cout << "l_str: " << l_str << std::endl << l_int << std::endl;
//	std::cout << salary << " " << wage << std::endl;
//	test3();
//	t_3_2();
//	t_4_2();
//	t_4_4();
//	t_5_2();
	t_5_3();
	return 0;
}


